﻿using LS.FrmUI.Dal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace LS.FrmUI
{
    public partial class FrmSearch : Form
    {
        public FrmSearch()
        {
            //设置窗体的双缓冲
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();

            InitializeComponent();

            //利用反射设置DataGridView的双缓冲
            Type dgvType = this.dataGridView1.GetType();
            PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
                BindingFlags.Instance | BindingFlags.NonPublic);
            pi.SetValue(this.dataGridView1, true, null);
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtISN.Text = "";
            txtKITID.Text = "";
            txtCName.Text = "";
            txtCPhone.Text = "";
            txtPtype.Text = "";
        }
        AttDal dal = new AttDal();
        private void btnSerach_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource= dal.GetResByKITIDAndISN(txtKITID.Text,txtCName.Text,txtCPhone.Text,txtISN.Text,txtPtype.Text);
            this.Text = "查询结果行数:" + dataGridView1.RowCount.ToString();
        }

        private void FrmSearch_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridView1.ReadOnly = true;
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void FrmSearch_FormClosing(object sender, FormClosingEventArgs e)
        {
            new FrmMain().Show();
        }
    }
}
